# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 17:07
# @Author  : qd
# @Email   : 1518603573@qq.com
# @File    : chance_add_page.py
# @Software: PyCharm
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
"""添加付款单界面"""
class ChanceAddPage(BasePage):
    url="/crm/index.php?m=business"
    # 负责人输入框定位器
    chance_input_owner_locator = (By.CSS_SELECTOR, "#owner_name")
    #选中对应的负责人的定位器
    chance_select_owner_locator = (By.CSS_SELECTOR, "#d_content > tr:nth-child(1) > td:nth-child(1) > input[type=radio]")
    # 负责人ok定位器
    chance_btn_ok_locator = (By.CSS_SELECTOR,"body > div:nth-child(19) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)")
    # 客户输入框的定位器
    chance_input_customer_locator = (By.CSS_SELECTOR, "#customer_name")
    # 选中对的客户的定位器
    chance_select_customer_locator = (By.CSS_SELECTOR, "#datas > tr > td:nth-child(1) > input[type=radio]:nth-child(1)")
    # ok定位器
    chance_customer_ok_locator = (By.CSS_SELECTOR,"body > div:nth-child(17) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)")
    # 商机金额定位器
    total_price_input_locator = (By.ID, "total_price")
    # 商机名称定位器
    chance_name_input_locator = (By.ID, "name")
    # 联系人输入框定位器
    contacts_name_input_locator = (By.ID, "contacts_name")
    # 选中对应的联系人定位器
    contacts_name_select_locator = (By.CSS_SELECTOR, "#data2 > tr > td:nth-child(1) > input[type=radio]")
    # ok定位器
    contacts_name_ok_locator = (By.CSS_SELECTOR, "body > div:nth-child(18) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)")
    # 线索来源定位器
    chance_source_select_locator = (By.ID, "origin")
    # 预计成交金额定位器
    estimate_price_locator = (By.ID, "estimate_price")
    # 保存按钮定位器
    chance_btn_submit_locator = (By.CSS_SELECTOR, "#form1 > table > tfoot > tr > td > input:nth-child(1)")

    """点击负责人输入框"""
    def click_chance_input_owner(self):
        self.driver.find_element(*self.chance_input_owner_locator).click()
    """选中对应的负责人"""
    def click_chance_select_owner(self):
        self.driver.find_element(*self.chance_select_owner_locator).click()
    """点击ok"""
    def click_chance_btn_ok(self):
        self.driver.find_element(*self.chance_btn_ok_locator).click()
    """点击客户姓名输入框"""
    def click_chance_input_customer(self):
        self.driver.find_element(*self.chance_input_customer_locator).click()
    """选中对的客户"""
    def click_chance_select_customer(self):
        self.driver.find_element(*self.chance_select_customer_locator).click()
    """点击Ok"""
    def click_chance_customer_ok(self):
        self.driver.find_element(*self.chance_customer_ok_locator).click()
    """输入商机金额"""
    def input_total_price(self,total_price):
        self.driver.find_element(*self.total_price_input_locator).send_keys(total_price)
    """输入商机名称"""
    def input_hance_name(self, chance_name):
        self.driver.find_element(*self.chance_name_input_locator).send_keys(chance_name)
    """点击联系人输入框"""
    def click_contacts_name_input(self):
        self.driver.find_element(*self.contacts_name_input_locator).click()

    """选中对应的联系人"""
    def click_contacts_name_select(self):
        self.driver.find_element(*self.contacts_name_select_locator).click()

    """点击OK"""
    def click_contacts_name_ok(self):
        self.driver.find_element(*self.contacts_name_ok_locator).click()

    """选择商机来源"""
    def chance_source_select(self,source_text):
        select_element = self.driver.find_element(*self.chance_source_select_locator)
        select_source = Select(select_element)
        select_source.select_by_visible_text(source_text)

    """输入预计成交价格名称"""
    def input_estimate_price(self, estimate_price):
        self.driver.find_element(*self.estimate_price_locator).send_keys(estimate_price)

    """点击保存"""
    def click_chance_btn_submit(self):
        self.driver.find_element(*self.chance_btn_submit_locator).click()
